package com.ec.system.modules.sys.controller;

import com.ec.core.common.core.api.Result;
import com.ec.core.common.core.api.ResponseMsg;
import com.ec.core.common.core.base.BasePageVO;
import com.ec.core.mybatis.groups.AddGroup;
import com.ec.core.mybatis.groups.DeleteGroup;
import com.ec.core.mybatis.groups.UpdateGroup;
import com.ec.core.secure.annotations.PreAuth;
import com.ec.system.modules.sys.dto.QueryPostDTO;
import com.ec.system.modules.sys.dto.SysPostDTO;
import com.ec.system.modules.sys.service.ISysPostService;
import com.ec.system.modules.sys.vo.SysPostVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 职位接口
 * @author: Eric Lee
 * @time: 2021/9/23 10:47
 */
@RestController
@RequestMapping("/post")
public class SysPostController {
    @Resource
    private ISysPostService sysPostService;
    /**
     *  岗位列表
     * @param listPostDTO
     * @return
     */
    @GetMapping("/list")
    @PreAuth("sys_post_view,sys_user_add,sys_user_edit")
    public Result<BasePageVO<SysPostVO>> listPost(QueryPostDTO listPostDTO){
        return ResponseMsg.success(sysPostService.listPost(listPostDTO));
    }


    /**
     *  添加操作
     * @param postDTO
     * @return
     */
    @PostMapping
    @PreAuth("sys_post_add")
    public Result<Void> addPost(@Validated(AddGroup.class)@RequestBody SysPostDTO postDTO){
        return ResponseMsg.status(sysPostService.addPost(postDTO));
    }

    /**
     *  修改操作
     * @param postDTO
     * @return
     */
    @PutMapping
    @PreAuth("sys_post_edit")
    public Result<Void> updatePost(@Validated(UpdateGroup.class)@RequestBody SysPostDTO postDTO){
        return ResponseMsg.status(sysPostService.updatePost(postDTO));
    }

    /**
     *  删除操作
     * @param postId
     * @return
     */
    @DeleteMapping("/{postId}")
    @PreAuth("sys_post_delete")
    public Result<Void> deletePost(@PathVariable Long postId){
        SysPostDTO postDTO = new SysPostDTO();
        postDTO.setPostId(postId);
        return ResponseMsg.status(sysPostService.deletePost(postDTO));
    }
}
